using NL.UI;

namespace NL.Advanced
{
    public class UIInfo_ItemList : UIInfo
    {
        protected override void _DoReset()
        {
            if (!this.enabled)//this.isActiveAndEnabled
            {
                return;
            }

            UIItemList cpntItemList = GetComponent<UIItemList>();
            if (cpntItemList != null)
            {
                cpntItemList.StopAllCoroutines();
                cpntItemList.CancelInvoke();
            }
            else
            {
                Container uiContainer = GetComponent<Container>();
                if (uiContainer != null)
                {
                    uiContainer.StopAllCoroutines();
                    uiContainer.CancelInvoke();
                }
            }

            if (this.gameObject == null || !this.gameObject.activeInHierarchy)
            {
                return;
            }

            base._DoReset();

            CancelInvoke("_DoResetContent");
            Invoke("_DoResetContent", 0.02f);
        }

        void _DoResetContent()
        {
            if (this.gameObject == null || !this.gameObject.activeInHierarchy)
            {
                return;
            }

            UIItemList cpntItemList = GetComponent<UIItemList>();
            if (cpntItemList != null)
            {
                cpntItemList.Set(_Value);
                if (cpntItemList.gameObject.activeInHierarchy)
                {
                    cpntItemList.Reset("");
                }
            }
            else
            {
                Container cpntItemContainer = GetComponent<Container>();
                if (cpntItemContainer != null)
                {
                    string itemstr = _Value.Replace("\"", "").Replace("'", "");
                    var datas = UIItemList._DECODE_Items(itemstr, NLConst.CHAR_ARRAY, NLConst.CHAR_INNER);// '|', ';');
                    cpntItemContainer.Set(datas);
                    cpntItemContainer.Reset();
                }
            }

        }
    }
}

